package com.handong.handdemo.util.connet;

import android.util.Log;

import com.handong.handdemo.base.ProgramApplication;
import com.handong.handdemo.entitiss.User;
import com.handong.handdemo.ui.view.LoginBottomDialog;
import com.handong.handdemo.util.SystemUtil;

import java.util.concurrent.Executors;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpUtil {
    private String TAG="HttpUtil";
    private Retrofit mRetrofit= new Retrofit.Builder()
            .baseUrl("https://111.230.245.184:8201/api/Request/PeocessRequest/")//base的网络地址  baseUrl不能为空,且强制要求必需以 / 斜杠结尾
            .addConverterFactory(GsonConverterFactory.create())//使用Gson解析
            .callbackExecutor(Executors.newSingleThreadExecutor())//使用单独的线程处理
            .build();
    UserApi userApi = mRetrofit.create(UserApi.class);

    private void initHttpBase() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl("https://111.230.245.184:8201/api/Request/PeocessRequest")//base的网络地址  baseUrl不能为空,且强制要求必需以 / 斜杠结尾
                .addConverterFactory(GsonConverterFactory.create())//使用Gson解析
                .callbackExecutor(Executors.newSingleThreadExecutor())//使用单独的线程处理
                .build();
    }


    public void loginHttp(String user,String pwd){
        Call<User> call = userApi.login(user,pwd, SystemUtil.getPhoneIMEI(ProgramApplication.getInstance()));
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                User user = response.body();

                Log.e(TAG, "onResponse: userName="+user.getName());
                Log.e(TAG, "onResponse: userPassrod="+user.getpName());
            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                new LoginBottomDialog().loginFail(t.toString());
                Log.e(TAG, "onFailure: 网络请求失败="+t.getMessage());

            }
        });
    }
}
